#include "stdafx.h"
#include "StageSystem.h"

#include "StageComponent.h"


namespace Be
{
	StageNode::StageNode(Entity* p_pEntity)
		: Node(p_pEntity)
	{
		m_StageComponent.Initialize(p_pEntity);
	}

	StageNode::~StageNode()
	{
	}

	void StageNode::CheckNextStage(std::wstring p_NextStageName)
	{
		if(p_NextStageName == m_StageName)
		{
			return;
		}

		ReleaseStage();

		InitStage(p_NextStageName);
	}

	bool StageNode::InitStage(std::wstring p_StageName)
	{
		m_StageName = p_StageName;

		return true;
	}

	void StageNode::ReleaseStage()
	{
	}
}

namespace Be
{
	StageSystem::StageSystem()
	{
	}

	StageSystem::~StageSystem()
	{
	}

	StageSystem& StageSystem::Inst()
	{
		static StageSystem l_Instance;

		return l_Instance;
	}

	void StageSystem::OnRegister(StageNode* p_pNode, const StageNode::Seed& p_rSeed)
	{
		assert(p_pNode != 0);

		p_pNode->m_StageComponent->SetNextStageName(p_rSeed.m_InitStageName);
	}

	void StageSystem::OnUnregister(StageNode* p_pNode)
	{
		assert(p_pNode != 0);
	}

	void StageSystem::OnUpdate(StageNode* p_pNode)
	{
		assert(p_pNode != 0);

		p_pNode->CheckNextStage(p_pNode->m_StageComponent->GetNextStageName());
	}
}
